package com;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: BGONZ8
 * Date: 9/23/11
 * Time: 4:19 PM
 * To change this template use File | Settings | File Templates.
 */
public class Main {


    public static void main(String[] args)  throws Exception {

        TestSession testSession = null;
        String rndId = "";
        DB db = new DB();
        db.execute("delete from INVALD_TRANS_LIN_ITM");
        db.execute("delete from INVALD_TRANS_HDR");
        db.execute("delete from TRANS_LIN_ITM");
        db.execute("delete from TRANS_HDR");
        db.close();
        try {
            testSession = new TestSession();
            List<String> srcs = util.getSourceSystems() ;
            //for( String src : srcs )
            String src = "GD";
            {
            //String src = "GD";
                //================  DROPBOX  ================
                rndId = util.getRandomTransactionID();
                DropBoxTestCase testCase1 = (DropBoxTestCase)testSession.addTestCase(new DropBoxTestCase());
                testCase1.setUserComment("Set Unit Code to an allotment that matches.");
                testCase1.getFeedService().setSourceSystem(src);
                testCase1.getTxFile().setSourceSystemCode(src);
                testCase1.getTxFile().setUnitCode("-1");
                testCase1.getTxFile().setTransactionID(rndId);
                testCase1.getTxFile().setCustomerNumber("124135154");
                testCase1.getSqlStmts().add("select  * from TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase1.getSqlStmts().add("select  * from INVALD_TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase1.submit();
                //================  DROPBOX ================
                rndId = util.getRandomTransactionID();
                DropBoxTestCase testCase2 = (DropBoxTestCase)testSession.addTestCase(new DropBoxTestCase());
                testCase2.setUserComment("Set Unit Code to a value that has no match in the allotment table.");
                testCase2.getFeedService().setSourceSystem(src);
                testCase2.getTxFile().setSourceSystemCode(src);
                testCase2.getTxFile().setUnitCode("-1999");
                testCase2.getTxFile().setTransactionID(rndId);
                testCase2.getTxFile().setCustomerNumber("124135154");
                testCase2.getSqlStmts().add("select  * from TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase2.getSqlStmts().add("select  * from INVALD_TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase2.submit();
               //================  DROPBOX  ================
                rndId = util.getRandomTransactionID();
                DropBoxTestCase testCase = (DropBoxTestCase)testSession.addTestCase(new DropBoxTestCase());
                testCase.setUserComment("Matching code for Sales Org.");
                testCase.getFeedService().setSourceSystem(src);
                testCase.getTxFile().setSourceSystemCode(src);
                testCase.getTxFile().setSalesOrg("-1");
                testCase.getTxFile().setTransactionID(rndId);
                testCase.getTxFile().setCustomerNumber("124135154");
                testCase.getSqlStmts().add("select  * from TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.getSqlStmts().add("select  * from INVALD_TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.submit();
               //================  DROPBOX  ================
                rndId = util.getRandomTransactionID();
                testCase = (DropBoxTestCase)testSession.addTestCase(new DropBoxTestCase());
                testCase.setUserComment("No matching code for Sales Org.");
                testCase.getFeedService().setSourceSystem(src);
                testCase.getTxFile().setSourceSystemCode(src);
                testCase.getTxFile().setSalesOrg("-1787");
                testCase.getTxFile().setTransactionID(rndId);
                testCase.getTxFile().setCustomerNumber("124135154");
                testCase.getSqlStmts().add("select  * from TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.getSqlStmts().add("select  * from INVALD_TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.submit();
               //================  DROPBOX  ================
                rndId = util.getRandomTransactionID();
                testCase = (DropBoxTestCase)testSession.addTestCase(new DropBoxTestCase());
                testCase.setUserComment("Matching code for Customer Number.");
                testCase.getFeedService().setSourceSystem(src);
                testCase.getTxFile().setSourceSystemCode(src);
                testCase.getTxFile().setTransactionID(rndId);
                testCase.getTxFile().setCustomerNumber("124135154");
                testCase.getSqlStmts().add("select  * from TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.getSqlStmts().add("select  * from INVALD_TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.submit();
               //================  DROPBOX  ================
                rndId = util.getRandomTransactionID();
                testCase = (DropBoxTestCase)testSession.addTestCase(new DropBoxTestCase());
                testCase.setUserComment("No matching code for Customer Number.");
                testCase.getFeedService().setSourceSystem(src);
                testCase.getTxFile().setSourceSystemCode(src);
                testCase.getTxFile().setCustomerNumber("-1787");
                testCase.getTxFile().setTransactionID(rndId);
                testCase.getSqlStmts().add("select  * from TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.getSqlStmts().add("select  * from INVALD_TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.submit();
               //================  DROPBOX  ================
                rndId = util.getRandomTransactionID();
                testCase = (DropBoxTestCase)testSession.addTestCase(new DropBoxTestCase());
                testCase.setUserComment("Matching code for Customer Number.");
                testCase.getFeedService().setSourceSystem(src);
                testCase.getTxFile().setSourceSystemCode(src);
                testCase.getTxFile().setTransactionID(rndId);
                testCase.getTxFile().setCompNumber("-1");
                testCase.getSqlStmts().add("select  * from TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.getSqlStmts().add("select  * from INVALD_TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.submit();
               //================  DROPBOX  ================
                rndId = util.getRandomTransactionID();
                testCase = (DropBoxTestCase)testSession.addTestCase(new DropBoxTestCase());
                testCase.setUserComment("No matching code for Customer Number.");
                testCase.getFeedService().setSourceSystem(src);
                testCase.getTxFile().setSourceSystemCode(src);
                testCase.getTxFile().setCompNumber("-2323");
                testCase.getTxFile().setTransactionID(rndId);
                testCase.getSqlStmts().add("select  * from TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.getSqlStmts().add("select  * from INVALD_TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.submit();

               //================  DROPBOX  ================
                rndId = util.getRandomTransactionID();
                testCase = (DropBoxTestCase)testSession.addTestCase(new DropBoxTestCase());
                testCase.setUserComment("Matching code for Customer Number.");
                testCase.getFeedService().setSourceSystem(src);
                testCase.getTxFile().setSourceSystemCode(src);
                testCase.getTxFile().setTransactionID(rndId);
                testCase.getTxFile().setCustomerRequestedDeliveryDate("2010-10-26T21:32:52");
                testCase.getSqlStmts().add("select  * from TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.getSqlStmts().add("select  * from INVALD_TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.submit();
               //================  DROPBOX  ================
                rndId = util.getRandomTransactionID();
                testCase = (DropBoxTestCase)testSession.addTestCase(new DropBoxTestCase());
                testCase.setUserComment("No matching code for Customer Number.");
                testCase.getFeedService().setSourceSystem(src);
                testCase.getTxFile().setSourceSystemCode(src);
                testCase.getTxFile().setCustomerRequestedDeliveryDate("2011-10-26T21:32:52");
                testCase.getTxFile().setTransactionID(rndId);
                testCase.getSqlStmts().add("select  * from TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.getSqlStmts().add("select  * from INVALD_TRANS_HDR where SRC_TRANS_ID= '" + rndId + "'" ) ;
                testCase.submit();
            }
            //================  REST GET ================
            rndId = util.getRandomTransactionID();
            RestGetTestCase restTestCase = (RestGetTestCase)testSession.addTestCase(new RestGetTestCase());
            restTestCase.setUserComment("It should return an XML.");
            restTestCase.setEndpoint("http://localhost:9090/thelocker/rest/assets.xml");
            restTestCase.setRequestParameters("assetId=-3&properties=emailAddresses");
            restTestCase.submit();
            //================  REST POST ================
            rndId = util.getRandomTransactionID();
            RestPostTestCase postTestCase = (RestPostTestCase)testSession.addTestCase(new RestPostTestCase());
            postTestCase.setUserComment("It should return an error.");
            postTestCase.setEndpoint("http://localhost:9090/thelocker/rest/assets.xml");
            String xmlFile = (new TransactionFile()).getXmlString();
            postTestCase.setPostData(xmlFile);
            postTestCase.submit();
            System.out.println("PROGRAM RUN == OK");
        } catch (Exception e) {
            System.out.println("PROGRAM ERROR: " + e.getMessage());
        }

        System.out.println(testSession.getSessionResult());
        testSession.writeToFile();
    }
}
